//
//  ZH_InsitutionViewModel.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/11/6.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_InsitutionViewModel.h"
//找机构
#define MechanismRecommend      @"/api/Mechanism/recommend"
//找机构详情
#define MechanismDetail         @"/api/Mechanism/detail"
//机构课程
#define MechanismCourse         @"/api/Mechanism/course"
//预约课程
#define MechanismReservation    @"/api/Mechanism/reservation"
//日期对应课程
#define MechanismDate_course    @"/api/Mechanism/date_course"
//有课日期
#define MechanismDate           @"/api/Mechanism/date"
//关注老师、机构
#define MechanismAttention      @"/api/Mechanism/attention"
@implementation ZH_InsitutionViewModel
//找机构
- (void)recommendResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:MechanismRecommend dictionaryParam:self.recommendParam withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
             resultArray = data[@"data"][@"data"];
        }
        if(resultArray.count > 0){
            [self.recommendArray removeAllObjects];
            [self.recommendArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }
    }];
}

//找机构详情
- (void)MechanismDetailResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:MechanismDetail dictionaryParam:self.mechanismDetailParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//机构课程
- (void)courseResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:MechanismCourse dictionaryParam:self.courseParam withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"][@"data"];
        }
        if(resultArray.count > 0){
            [self.courseArray removeAllObjects];
            [self.courseArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }

    }];
}

//预约课程
- (void)reservationResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:MechanismCourse dictionaryParam:self.reservationParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//日期对应课程
- (void)dataCourseResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:MechanismDate_course dictionaryParam:self.dataCourseParam withResultBlock:^(NSString *code, NSString *message, id data) {
        
    }];
}

//有课日期
- (void)dateResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:MechanismDate dictionaryParam:self.dateParam withResultBlock:^(NSString *code, NSString *message, id data) {
        
    }];
}

//关注老师、机构
- (void)attentionResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:MechanismAttention dictionaryParam:self.attentionParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}
#pragma mark - getter,setter
//找机构
- (NSMutableDictionary *)recommendParam{
    if (!_recommendParam) {
        _recommendParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_recommendParam setObject:@"" forKey:@"lat"];
        [_recommendParam setObject:@"" forKey:@"lng"];
        [_recommendParam setObject:@"" forKey:@"cate"];
        [_recommendParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_recommendParam setObject:@"" forKey:@"keywords"];
    }
    return _recommendParam;
}
- (NSMutableArray *)recommendArray{
    if (!_recommendArray) {
        _recommendArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _recommendArray;
}

//找机构详情
- (NSMutableDictionary *)mechanismDetailParam{
    if (!_mechanismDetailParam) {
        _mechanismDetailParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_mechanismDetailParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_mechanismDetailParam setObject:@"" forKey:@"id"];
        [_mechanismDetailParam setObject:@"" forKey:@"type"];
    }
    return _mechanismDetailParam;
}

//机构课程
- (NSMutableDictionary *)courseParam{
    if (!_courseParam) {
        _courseParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_courseParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_courseParam setObject:@"" forKey:@"id"];
    }
    return _courseParam;
}
- (NSMutableArray *)courseArray{
    if (!_courseArray) {
        _courseArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _courseArray;
}

//预约课程
- (NSMutableDictionary *)reservationParam{
    if (!_reservationParam) {
        _reservationParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_reservationParam setObject:@"" forKey:@"token"];
        [_reservationParam setObject:@"" forKey:@"id"];
        [_reservationParam setObject:@"" forKey:@"course_id"];
    }
    return _reservationParam;
}

//日期对应课程
- (NSMutableDictionary *)dataCourseParam{
    if (!_dataCourseParam) {
        _dataCourseParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_dataCourseParam setObject:@"" forKey:@"id"];
        [_dataCourseParam setObject:@"" forKey:@"token"];
        [_dataCourseParam setObject:@"" forKey:@"date"];
    }
    return _dataCourseParam;
}
- (NSMutableArray *)dataCourseArray{
    if (!_dataCourseArray) {
        _dataCourseArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _dataCourseArray;
}

//有课日期
- (NSMutableDictionary *)dateParam{
    if (!_dateParam) {
        _dateParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_dateParam setObject:@"" forKey:@"id"];
    }
    return _dateParam;
}
- (NSMutableArray *)dateArray{
    if (!_dateArray) {
        _dateArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _dateArray;
}

//关注老师、机构
- (NSMutableDictionary *)attentionParam{
    if (!_attentionParam) {
        _attentionParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_attentionParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_attentionParam setObject:@"" forKey:@"id"];
    }
    return _attentionParam;
}
@end
